<!--
 * @Author: WangLong
 * @Date: 2024-01-29 09:23:51
 * @LastEditTime: 2024-03-06 17:19:12
 * @LastEditors: WangLong
 * @Description: 
 * @FilePath: \front_erp\src\views\stock\returnApply\dtl.vue
-->
<template>
  <div v-loading="detailInfoShow">
    <div class="requestAdd" v-if="!selectionMaterialShow">
      <!-- 筛选按钮 -->
      <div class="search-button">
        <template v-if="checkStatus != 3">
          <el-button
            v-if="pageType === 'audit' && route.name === 'ReturnReview'"
            class="btn save"
            @click="handleCheckBtn2(projectFormRef, 3, '同意')"
            ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
            >同意</el-button
          >
          <el-button
            v-if="pageType === 'audit' && route.name === 'ReturnReview'"
            class="btn withdraw"
            @click="handleCheckBtn2(projectFormRef, 4, '拒绝')"
            ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
            >拒绝</el-button
          >

          <el-button
            v-if="pageType === 'audit' && route.name === 'ReturnReview'"
            class="btn withdraw"
            @click="handleCheckBtn2(projectFormRef, 6, '驳回')"
            ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
            >驳回</el-button
          >
        </template>
        <el-button
        v-if="activeName == 'approval' && flowInfoList.length"
        @click="handleEvaluate()"
        class="btn save"
        ><el-icon class="icon" color="#fff"> <Comment /> </el-icon
        >评论</el-button
      >
        <el-button v-if="activeName == 'approval' && flowInfoList.length" @click="handlePrint()" v-print="prints" class="btn add"
        ><el-icon class="icon" color="#fff"> <Printer /> </el-icon
        >打印</el-button
      >
        <el-button class="btn direction" @click="handleBack"
          ><el-icon class="icon" color="#fff"> <Back /> </el-icon
          >返回</el-button
        >
      </div>
      <!-- 内容信息 -->
      <el-tabs type="border-card" v-model="activeName">
        <el-tab-pane label="申请信息" name="info">
          <template v-slot:label>
            {{ route.name === "ReturnReview" ? "申请信息" : "退库信息" }}
          </template>
          <el-collapse v-model="activeNames">
            <!-- 基础信息 -->
            <el-collapse-item name="1" class="transform-down">
              <template #title>
                <span class="circle"></span>
                <span class="collapse-title"
                  >{{
                    pageType !== "detail"
                      ? pageType === "audit"
                        ? "审核"
                        : "编辑"
                      : "查看"
                  }}退库信息</span
                >
              </template>
              <div class="request-info">
                <el-form
                  :model="requestForm"
                  ref="requestFormRef"
                  label-width="100px"
                  v-enterToNext
                  :disabled="
                    pageType === 'detail' ||
                    pageType === 'check' ||
                    pageType === 'audit'
                  "
                >
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="退库编号：">
                        <el-input
                          disabled
                          v-model="requestForm.stockReturnCode"
                          placeholder="自动获取"
                          clearable
                          style="width: 100%"
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="入库批次：">
                        <el-input
                          style="width: 100%"
                          v-model="requestForm.batchCode"
                          placeholder="自动获取"
                          clearable
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="申请日期：" label-width="120px">
                        <el-date-picker
                          v-model="requestForm.applicantDate"
                          format="YYYY/MM/DD HH:mm:ss"
                          style="width: 100%"
                          class="search-input"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          type="datetime"
                          placeholder="请选择"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="申请人：">
                        <el-select
                          v-model="requestForm.applicantId"
                          placeholder="请选择"
                          clearable
                          style="width: 100%"
                          class="search-input"
                          @change="handleUserChange"
                        >
                          <el-option
                            v-for="dict in userList"
                            :key="dict.userId"
                            :label="dict.nickName"
                            :value="dict.userId"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="申请部门：">
                        <el-input
                          disabled
                          style="width: 100%"
                          v-model="requestForm.deptName"
                          placeholder="自动获取"
                          clearable
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="退库类型：">
                        <el-select
                          v-model="requestForm.stockReturnType"
                          placeholder="请选择退库类型"
                          clearable
                          style="width: 100%"
                          class="search-input"
                        >
                          <el-option
                            v-for="dict in outStatusList"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="关联出库单：" label-width="120px">
                        <el-autocomplete
                          popper-class="autoclass"
                          v-model="requestForm.deliveryApplyCode"
                          :fetch-suggestions="querySearch"
                          placeholder="请选择"
                          @focus="handleAutoCompleteFocus('outOrder')"
                          @select="handleOutOrderSelect"
                          style="width: 100%"
                          clearable
                        >
                          <template #default="{ item }">
                            <div class="auto-top" style="display: flex">
                              <div style="display: flex; width: 140px">
                                出库编号
                              </div>
                              <div class="auto-item">申请人</div>
                              <!-- <div class="auto-item">用途类型</div>
                              <div class="auto-item">关联项目</div> -->
                            </div>
                            <div style="display: flex; width: 500px">
                              <div
                                class="auto-item"
                                :title="item.deliveryApplyCode"
                                style="display: flex; width: 170px"
                              >
                                {{ item.deliveryApplyCode }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.applicantName"
                              >
                                {{ item.applicantName }}
                              </div>
                              <!-- <div
                                class="auto-item"
                                :title="item.applicantTypeName"
                              >
                                {{ item.applicantTypeName }}
                              </div>
                              <div class="auto-item" :title="item.remarks">
                                {{ item.remarks }}
                              </div> -->
                            </div>
                          </template>
                        </el-autocomplete>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="原项目：">
                        <el-autocomplete
                          popper-class="autoclass"
                          v-model="requestForm.projectName"
                          :fetch-suggestions="querySearch"
                          placeholder="请选择"
                          @focus="handleAutoCompleteFocus('project')"
                          @select="handleProjectSelect"
                          style="width: 100%"
                          clearable
                        >
                          <template #default="{ item }">
                            <div class="auto-top" style="display: flex">
                              <div style="display: flex; width: 140px">
                                项目编号
                              </div>
                              <div class="auto-item">项目名称</div>
                              <div class="auto-item">项目类别</div>
                              <div class="auto-item">项目类型</div>
                            </div>
                            <div style="display: flex; width: 500px">
                              <div
                                class="auto-item"
                                :title="item.projectCode"
                                style="display: flex; width: 170px"
                              >
                                {{ item.projectCode }}
                              </div>
                              <div class="auto-item" :title="item.projectName">
                                {{ item.projectName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.projectCategoryName"
                              >
                                {{ item.projectCategoryName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.projectTypeName"
                              >
                                {{ item.projectTypeName }}
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="备注：">
                        <el-input
                          style="width: 100%"
                          v-model="requestForm.remarks"
                          placeholder=""
                          type="textarea"
                          clearable
                          maxlength="2000"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="附件：" prop="businessLicense">
                        <Upload
                          :fileList="requestForm.fileList"
                          :isFull="true"
                          :showButton="true"
                          :isCanDelete="false"
                          :disabled="true"
                          @success="(result) => uploadSuccess(result, 1)"
                          @deleteFile="(result) => uploadRemove(result, 1)"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </el-collapse-item>
            <!-- 物料信息 -->
            <el-collapse-item
              name="2"
              style="position: relative"
              class="transform-down"
            >
              <template #title>
                <span class="circle"></span>
                <span class="collapse-title">物料列表</span>
                <div class="nofixed-search-button button-position">
                  <el-button
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    style="width: 150px"
                    class="btn submit"
                    @click.stop="handleQrcode()"
                    >下载全部二维码</el-button
                  >
                </div>
              </template>
              <div class="contact-info">
                <!-- 表格数据 -->
                <el-table
                  :data="requestForm.dtlList"
                  border
                  :height="'180px'"
                  :header-cell-style="{ 'text-align': 'center' }"
                  show-summary
                  sum-text="合计"
                  :summary-method="getSummaries"
                >
                  <!-- 操作模式 -->
                  <el-table-column
                    v-if="
                      checkStatus == 3 &&
                      route.name == 'ReturnReview' &&
                      pageType == 'check'
                    "
                    label="操作"
                    align="center"
                    :show-overflow-tooltip="true"
                    width="100px"
                  >
                    <template #default="{ row, $index }">
                      <div
                        class="table-operate"
                        v-if="row.stockReturnQuantity != row.inQty"
                      >
                        <el-button
                          style="background-color: #b0e0e6"
                          @click="handleOperate(row, $index)"
                          >入库</el-button
                        >
                      </div>
                      <div class="table-operate" v-else>
                        <el-button style="background-color: #ccc" disabled
                          >已入库</el-button
                        >
                      </div>
                    </template></el-table-column
                  >
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="主设备物资序列号"
                    prop="materialNumber"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  >
                    <!-- <template #default="{ row, $index }">
                      <div class="table-operate">
                        <el-button @click="handleQrcode(row, $index)"
                          >查看</el-button
                        >
                      </div>
                    </template> -->
                  </el-table-column>
                  <el-table-column
                    label="序号"
                    type="index"
                    :show-overflow-tooltip="true"
                    min-width="60"
                  />
                  <el-table-column
                    label="物料编号"
                    prop="materialCode"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  >
                    <template #default="{ row }">
                      <span>{{
                        row.materialCode ? row.materialCode : "--"
                      }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="物料名称"
                    prop="materialName"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  />
                  <el-table-column
                    label="出厂型号"
                    prop="factoryCode"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  />
                  <el-table-column
                    label="技术参数"
                    prop="technologyParameter"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  />
                  <el-table-column
                    label="单位"
                    prop="materialUnitName"
                    :show-overflow-tooltip="true"
                  />
                  <el-table-column
                    label="采购单价"
                    prop="purchasePrice"
                    min-width="160"
                  >
                  </el-table-column>
                  <!-- <el-table-column
                    v-if="pageType == 'detail' || pageType == 'audit'"
                    label="退库数量"
                    prop="stockReturnQuantity"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  /> -->
                  <!--      v-if="pageType == 'check' && route.name == 'ReturnReview'" -->
                  <el-table-column
                    label="申请退库数量"
                    prop="stockReturnQuantity"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  />
                  <!-- pageType !== 'detail' &&  -->
                  <el-table-column
                    v-if="route.name == 'ReturnReview'"
                    label="已入库数量"
                    prop="inQty"
                    :show-overflow-tooltip="true"
                    min-width="160"
                  />

                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="退库编号"
                    prop="stockReturnCode"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库批次"
                    prop="batchCode"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库人"
                    prop="applicantName"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库部门"
                    prop="deptName"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库日期"
                    prop="applicantDate"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库仓位"
                    prop="warehouseCode"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="授权有效期"
                    prop="validityPeriod"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="厂家质保期"
                    prop="expireDate"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    v-if="
                      route.name === 'ReturnReview' && pageType === 'detail'
                    "
                    label="入库图片"
                    prop=""
                    min-width="120"
                  >
                    <template #default="{ row }">
                      <div v-if="row.fileList" class="image-content">
                        <el-image
                          v-for="(item, index) in row.fileList"
                          :key="index"
                          :preview-teleported="true"
                          style="width: 50px; height: 50px; margin-right: 5px"
                          :src="item.url"
                          :preview-src-list="showImg(item.url)"
                        >
                          <template #error>
                            <div class="image-slot">
                              <el-icon><icon-picture /></el-icon>
                            </div>
                          </template>
                        </el-image>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column label="备注" prop="remarks" min-width="120">
                  </el-table-column>
                </el-table>
              </div>
            </el-collapse-item>
          </el-collapse>
        </el-tab-pane>
        <el-tab-pane label="审批进度" name="approval">
        <template v-if="requestForm.auditList.length">
          <div class="contact-info" id="print-iframe" >
        <!-- 步骤栏 -->
        <div :class="!printFlag? 'steps-box' : 'steps-print-box '">
            <el-steps
              :class="flowInfoList.length>7 ? 'BigSteps' : 'SmallSteps'"
              :active="flowingStep"
              
              finish-status="success"
            >
              <el-step v-for="(item, index) in flowInfoList" :key="index">
                <template #title>
                  <span :title="item.name">
                    {{ item.name }}
                  </span>
                </template>
                <template #description>
                  <div>
                    <p class="ription">{{ item.auditDate }}</p>
                    <p class="ription">{{ item.auditEmp }}</p>
                  </div>
                </template>
              </el-step>
            </el-steps>
          </div>
            <!-- 表格数据 -->
            <el-table
              :data="requestForm.auditList"
              border
              :height="'100%'"
              :header-cell-style="{ 'text-align': 'center' }"
              sum-text=""
            >
              <!-- 操作模式 -->
              <el-table-column label="流程节点" prop="name" min-width="120">
              </el-table-column>
              <el-table-column
                label="审核人"
                prop="createUserName"
                min-width="120"
              >
              </el-table-column>
              <el-table-column
                label="审核时间"
                prop="createTime"
                min-width="120"
              >
              </el-table-column>
              <el-table-column
                label="审核意见"
                prop="resultName"
                min-width="120"
              >
              </el-table-column>
              <el-table-column label="审核备注" prop="remark" min-width="120">
              </el-table-column>
            </el-table>
          </div>
           <!-- 评论 -->
           <el-table
            style="margin-top: 60px"
            :data="evaluateList"
            border
            :height="'100%'"
            :header-cell-style="{ 'text-align': 'center' }"
            sum-text=""
          >
            <!-- 操作模式 -->
            <el-table-column label="评论内容" prop="content" min-width="500">
            </el-table-column>
            <el-table-column
              label="评论人"
              prop="createUserName"
              min-width="120"
            >
            </el-table-column>
            <el-table-column label="评论时间" prop="createTime" min-width="120">
            </el-table-column>
          </el-table>
        </template>
          <div v-else>
            暂无审核
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div v-else class="search-button">
      <el-button class="btn direction" @click="handleBack('checkDtl')"
        ><el-icon class="icon" color="#fff"> <Back /> </el-icon
        >返回</el-button
      >
    </div>
    <SelectionReturnMaterial
      ref="selectionReturnMaterial"
      v-if="selectionMaterialShow"
      @refreshReturnList="gethandlelInfo"
      v-model:selectionMaterialShow="selectionMaterialShow"
    />
    <el-dialog
      v-model="dialogVisible"
      title="主设备序列号"
      width="36%"
      :close-on-click-modal="false"
    >
      <QrCodeInfo :qrcodeData="qrcodeData" />
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>

    <el-dialog
      :title="title"
      v-model="auditDialogShow"
      width="600px"
      append-to-body
    >
      <el-form-item label="审核备注：" label-width="90">
        <el-input
          style="width: 100%"
          v-model="auditRemark"
          placeholder=""
          type="textarea"
          maxlength="2000"
          clearable
        />
      </el-form-item>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            style="color: #fff; background-color: rgba(67, 207, 124, 1)"
            v-if="auditResult == 3"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >同意</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 4"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >拒绝</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 6"
            @click="saveCheck()"
            v-loading="loadingCheck"
          >
            驳回</el-button
          >
          <el-button style="background-color: #fff" @click="closeAudit()"
            >取 消</el-button
          >
        </div>
      </template>
    </el-dialog>
    <el-dialog
      :title="''"
      v-model="evaluateDialogShow"
      width="600px"
      append-to-body
    >
      <el-form-item label="评论内容：" label-width="90">
        <el-input
          style="width: 100%"
          v-model="evaluateInfo"
          placeholder=""
          type="textarea"
          rows="5"
          maxlength="500"
          clearable
        />
      </el-form-item>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            style="color: #fff; background-color: rgba(67, 207, 124, 1)"
            @click="saveEvaluate()"
            >保存</el-button
          >

          <el-button style="background-color: #fff" @click="closeEvaluate()"
            >取 消</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { addEvaluateApi, getEvaluateListApi } from "@/api/pub.js";
import { getUserListApi } from "@/api/information/customer";
import { getDictsApi } from "@/api/dict";
import { autoComplete } from "@/api/pub";
import SelectionReturnMaterial from "./selectionReturnMaterial";
import Upload from "@/components/Upload/index";
import QrCodeInfo from "@/components/qrCode/index";
import { getReturnStock, checkReturnApi } from "@/api/stock/returnapply";
import { ElMessage, ElMessageBox } from "element-plus";
const props = defineProps({
  // 操作类型
  pageType: {
    type: String,
    default: "add",
  },
});
// 路由
const route = useRoute();
const emit = defineEmits([
  // 客户新增组件显隐
  "dtlShow",
  // 更新客户新增组件显隐
  "update:dtlShow",
  // 刷新父组件表格数据
  "refreshList",
]);
// 详情加载效果
const detailInfoShow = ref(false);
const activeName = ref('info')
// 折叠栏默认展开
const activeNames = ref(["1", "2", "3"]);
// 退库表单引用
const requestFormRef = ref();
// 退库类型状态
const outStatusList = ref([]);
//退库审核物料组件
const selectionReturnMaterial = ref();
// 退库审核物料信息显隐
const selectionMaterialShow = ref(false);

const loadingCheck = ref(false);
// 选择审核
const auditDialogShow = ref(false);
//控制查看二维码弹窗
const dialogVisible = ref(false);
//主设备物资序列号数据
const qrcodeData = ref([]);
//审核进度数据
const flowInfoList = ref([]);
//当前进度
const flowingStep = ref(0);

// 评论
const evaluateDialogShow = ref(false);
// 评论内容
const evaluateInfo = ref("");
// 评论列表
const evaluateList = ref([]);

// 退库表单数据模板
const requestFormTemplate = {
  deliveryApplyCodeww: null, //入库编号
  batchCode: null, //入库批次
  applicantDate: "", //申请日期
  applicantId: null, //申请人
  deptName: "", //申请部门
  stockReturnType: null, //退库类型
  remarks: "", //备注
  deliveryApplyCode: "", //关联出库单号
  deliveryApplyId: null, //关联出库工单id
  projectName: "", //原项目名
  projectId: null, //原项目id
  fileList: [],
  dtlList: [],
  inList: [],
  auditList: [],
};
const data = reactive({
  // 客户表单
  requestForm: JSON.parse(JSON.stringify(requestFormTemplate)),
  autoType: "",
  // 用户列表
  userList: [],
  auditRemark: "",
  auditResult: "",
  applyId: "",
});

const { requestForm, userList, autoType, auditRemark, auditResult, applyId } =
  toRefs(data);

  
import print from "vue3-print-nb";

// 使用自定义指令
const vPrint = print;
const printFlag = ref(false);

let prints = {
  id: "print-iframe",
  popTitle: "配置页眉标题", // 打印配置页上方的标题
  extraHead: "", // 最上方的头部文字，附加在head标签上的额外标签，使用逗号分割
  preview: false, // 是否启动预览模式，默认是false
  previewTitle: "预览的标题", // 打印预览的标题
  previewPrintBtnLabel: "预览结束，开始打印", // 打印预览的标题下方的按钮文本，点击可进入打印
  zIndex: 20002, // 预览窗口的z-index，默认是20002，最好比默认值更高
  previewBeforeOpenCallback() {
    console.log("正在加载预览窗口！");
  }, // 预览窗口打开之前的callback
  previewOpenCallback() {
    console.log("已经加载完预览窗口，预览打开了！");
  }, // 预览窗口打开时的callback
  // 开始打印之前的callback
  beforeOpenCallback() {
    
    console.log("开始打印之前！");
   
  },
  openCallback() {
    console.log("执行打印了！");
  }, // 调用打印时的callback
  closeCallback() {
    console.log("关闭了打印工具！");
    printFlag.value= false
  }, // 关闭打印的callback(无法区分确认or取消)
  clickMounted() {
    console.log("点击v-print绑定的按钮了！");
    
  },
  standard: "",
  extarCss: "",
};

const handlePrint = ()=>{
  printFlag.value = true
}

// 处理评论按钮点击
const handleEvaluate = () => {
  evaluateDialogShow.value = true;
};

// 保存评论
const saveEvaluate = async () => {
  if (!evaluateInfo.value) return ElMessage.info("请输入评论内容！");
  const data = {
    businessId: requestForm.value.stockReturnId,
    content: evaluateInfo.value,
    modelType: 10,
  };
  const result = await addEvaluateApi(data);
  if (result.code === 200) {
    ElMessage.success(result.msg);
    evaluateDialogShow.value = false;
    evaluateInfo.value = "";
    getEvaluateList()
  }
};

// 关闭评论弹窗
const closeEvaluate = () => {
  evaluateDialogShow.value = false;
  evaluateInfo.value = "";
};

// 获取评价列表
const getEvaluateList = async () => {
  const data = {
    businessId: requestForm.value.stockReturnId,
    modelType: 10,
  };
  const result = await getEvaluateListApi(data);
  evaluateList.value = result.data || []
};


/**
 * @description: 处理审核状态相关按钮
 * @param {String} type  类型
 * @param {String} title 标题
 */

const handleCheckBtn2 = (requestFormRef, type, title) => {
  auditRemark.value = "";
  if (type == 3) {
    auditRemark.value = "同意";
  }

  auditResult.value = type;
  (applyId.value = requestForm.value.stockReturnId),
    (auditDialogShow.value = true);
  loadingCheck.value = false;
};

const saveCheck = async () => {
  if (auditRemark.value === null || auditRemark.value === "") {
    ElMessage.error("审核备注不能为空");
    return;
  }

  const obj = {
    approvalStatus: auditResult.value,
    stockReturnId: applyId.value,
    auditRemark: auditRemark.value,
  };

  try {
    loadingCheck.value = true;
    const res = await checkReturnApi(obj);

    auditDialogShow.value = false;

    if (res.code === 200) {
      ElMessage.success(res.msg);
      // contractForm.value = JSON.parse(JSON.stringify(contractFormTemplate));
    } else {
      ElMessage.error(res.msg);
    }
    loadingCheck.value = false;
    emit("update:dtlShow", false);
    emit("refreshList", false);
  } catch (error) {
    loadingCheck.value = false;
    emit("update:dtlShow", false);
    emit("refreshList", false);

    // ElMessage.error(error);
  }
};

const closeAudit = () => {
  auditRemark.value = "";
  auditResult.value = "";
  applyId.value = "";
  auditDialogShow.value = false;
};

const handleCheckBtn = (contractFormRef, type, title) => {
  ElMessageBox.confirm(`确定${title}以上数据吗？`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    confirmButtonClass: "confirmBtnClass",
    cancelButtonClass: "cancelBtnClass",
  })
    .then(async () => {
      const obj = {
        approvalStatus: type,
        stockReturnId: requestForm.value.stockReturnId,
      };
      const res = await checkReturnApi(obj);
      if (res.code === 200) {
        emit("update:dtlShow", false);
        emit("refreshList", false);
        ElMessage.success(res.msg);
      } else {
        ElMessage.error(res.msg);
      }
    })
    .catch(() => {});
};
/**
 * @description: 返回
 */
const handleBack = (val) => {
  emit("update:dtlShow", false);
  emit("refreshList", false);
  requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
  if (val === "checkDtl") {
    emit("refreshList", false);
  }
};

/**
 * @description: 处理合计
 */
 const getSummaries = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    }
    const values = data.map((item) => Number(item[column.property]));
    // 只对amount这一列进行总计核算。
    if (column.property === "stockReturnQuantity"||column.property === "inQty") {
      if (!values.every((value) => isNaN(value))) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        // sums[index] = sums[index].toFixed(2); // 保留2位小数，解决小数列合计精度缺失的问题
        // sums[index] += "元";
      } else {
        sums[index] = "";
      }
    }
  });
  return sums;
};

/**
 * @description: 处理详情信息
 * @param {Number} id
 * @param checkStatus  (0:未提交,1:待审核,2:审核中,3:已通过,4:未通过,5:已撤销,6:已驳回)
 */
let checkStatus = ref(null);
let returnAppliId = null;
const handleDetailInfo = async (row) => {
  try {
    returnAppliId = row.stockReturnId;
    checkStatus.value = row.checkStatus;
    detailInfoShow.value = true;
    const res = await getReturnStock({
      stockReturnId: row.stockReturnId,
      checkStatus: props.pageType === "check" ? null : row.checkStatus,
    });
    if (res.code == 200) {
      requestForm.value = res.data;
      getEvaluateList()
      if(res.data.auditList.length){
        flowInfoList.value = res.data.auditList[0].chartVo.flowList;
        flowingStep.value = res.data.auditList[0].chartVo.flowingStep;
      }
    }
    detailInfoShow.value = false;
  } catch (error) {
    detailInfoShow.value = false;
  }
};
/**
 * @description: 入库修改后关闭刷新
 * @param {Number} returnAppliId
 */
const gethandlelInfo = async () => {
  const res = await getReturnStock({ stockReturnId: returnAppliId });
  if (res.code == 200) {
    requestForm.value = res.data;
  }
};
/**
 * @description: 处理退库审核（入库信息）
 */
const handleOperate = async (row, tabIndex) => {
  selectionMaterialShow.value = true;
  nextTick(() => {
    selectionReturnMaterial.value.handleMaterial(row);
  });
};
/**
 * @description: 获取字典
 */
async function getDicts() {
  // 退库类型
  await getDictsApi("erp_stock_return_type").then((res) => {
    if (res.code === 200) {
      outStatusList.value = res.data;
    }
  });
  //申请人列表
  await getUserListApi({}).then((res) => {
    if (res.length > 0) {
      userList.value = res;
    }
  });
}
/**
 * @description: 处理人员选择
 * @param {Number} value 选择值
 */
const handleUserChange = (value) => {
  if (value) {
    const selectUser = userList.value.find((item) => item.userId === value);
    if (selectUser) {
      requestForm.value.deptName = selectUser.dept.deptName;
    }
  } else {
    requestForm.value.deptName = "";
  }
};
const handleAutoCompleteFocus = (value) => {
  autoType.value = value;
};

const querySearch = (queryStr, cb) => {
  // requestForm.value.projectId = "";
  // requestForm.value.projectName = "";
  // const results = projectList.value;
  // cb(results);
  if (queryStr === null || queryStr === "") {
    if (autoType.value == "project") {
      requestForm.value.projectId = "";
      requestForm.value.projectName = "";
    }
    if (autoType.value == "outOrder") {
      requestForm.value.deliveryApplyId = "";
      requestForm.value.deliveryApplyCode = "";
    }

    cb([]);
  } else {
    autoComplete(queryStr, autoType.value).then((response) => {
      const list = response;
      cb(list);
    });
  }
};
/**
 * @description: 原项目下拉选择
 */
const handleProjectSelect = (value) => {
  requestForm.value.projectId = value.id;
  requestForm.value.projectName = value.projectName;
};
/**
 * @description: 关联出库工单下拉选择
 */
const handleOutOrderSelect = (value) => {
  requestForm.value.deliveryApplyId = value.id;
  requestForm.value.deliveryApplyCode = value.deliveryApplyCode;
};
/**
 * @description: 文件上传成功处理
 * @param {Object} response 文件信息
 */
function uploadSuccess(response) {
  requestForm.value.fileList.push({ ...response, businessType: 6 });
}

/**
 * @description: 删除文件
 * @param {Number} index 当前文件索引
 */
function uploadRemove(index) {
  requestForm.value.fileList.splice(index, 1);
}
/**
 * @description: 查看主设备物资序列号
 */
const handleQrcode = async (row) => {
  // qrcodeData.value = [];
  // dialogVisible.value = true;
  // qrcodeData.value.push({
  //   materialNumber: row.materialNumber,
  // });
  if (requestForm.value.dtlList.length > 0) {
    qrcodeData.value = [];

    requestForm.value.dtlList.forEach((item) => {
      if (item.materialNumber)
        qrcodeData.value.push({
          materialNumber: item.materialNumber,
        });
    });
    if (qrcodeData.value.length > 0) {
      dialogVisible.value = true;
    } else {
      ElMessage.error("暂无数据");
    }
  }
};
const showImg = (img) => {
  let imgArr = [];
  imgArr.push(img);
  return imgArr;
};

onMounted(() => {
  getDicts();
});
defineExpose({
  handleDetailInfo,
});
</script>

<style lang="scss" scoped>
.requestAdd {
  padding: 20px 20px;
  width: 100%;
  height: 100%;
  .request-info {
    padding: 20px 20px 5px 20px;
    background-color: #f0f0f0;
    margin: 10px 0;
  }
  .contact-info {
    padding-top: 20px;
    .ription {
      color: #8f8f8f;
      line-height: 16px;
      font-size: 12px;
    }
    :deep(.el-step__head.is-success) {
      color: #3399ff;
      border-color: #3399ff;
      position: relative;
    }
    :deep(.el-step__title) {
      font-size: 16px;
      line-height: 38px;
      position: absolute;
      top: -38px;
      width: 140px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    :deep(.el-step__title.is-success) {
      color: #3399ff;
    }
    .table-operate {
      cursor: pointer;
      .el-button {
        height: 28px;
      }
    }
  }

  :deep(.el-table) {
    th.el-table__cell {
      background: #f8f8f8 !important;
    }
  }
  :deep(.el-date-editor.el-input, .el-date-editor.el-input__wrapper) {
    width: 268px !important;
    height: 34px !important;
  }
  .search-input {
    width: 268px;
    height: 34px;
  }
  .image-content {
    width: 100%;
    line-height: 0px;
    overflow: auto;
  }
}
.auto-top {
  width: 100%;
  position: absolute;
  top: 0px;
  display: flex;
  font-weight: bold;
}
.auto-item {
  width: 125px;
  text-align: center;
  white-space: nowrap; /* 禁止换行 */
  overflow: hidden; /* 隐藏超出部分 */
  text-overflow: ellipsis; /* 使用省略号表示超出部分 */
}
.el-autocomplete .el-autocomplete-suggestion {
  max-height: 200px; /* 设置最大高度 */
  overflow-y: auto; /* 超出高度时显示滚动条 */
}
.el-table {
  border: var(--el-table-border);
}
</style>
